// pages/index/index.js
import Dialog from '../../component/vant/dialog/dialog';
let util = require('../../utils/util.js');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    person:{
      
    },
    teaTypes:[
      {
        name:'花茶',
        img:'../../images/hc_01.png'
      },
      {
        name: '普洱茶',
        img: '../../images/prc_02.png'
      },
      {
        name: '白茶',
        img: '../../images/bc_03.png'
      },
      {
        name: '红茶',
        img: '../../images/hc_04.png'
      },
      {
        name: '黑茶',
        img: '../../images/hc_05.png'
      },
      {
        name: '乌龙茶',
        img: '../../images/wlc_06.png'
      },
      {
        name: '绿茶',
        img: '../../images/lc_07.png'
      },
      {
        name: '保健茶',
        img: '../../images/bjc_08.png'
      },
    ]
  },

  toStore(e){
    let index = e.currentTarget.dataset.index;
    console.log(index);
    app.globalData.teaType = index;
    wx.switchTab({
      url: '../store/store'
    })
  },

  callMe(){
    let mobile = this.data.person.mobile
    Dialog.confirm({
      title: '提示',
      message: '确定拨打电话：'+mobile +'吗？',
      closeOnClickOverlay: true
    }).then(() => {
      // on confirm
      wx.makePhoneCall({
        phoneNumber: mobile// 仅为示例，并非真实的电话号码
      })
    }).catch(() => {
      // on cancel
    });
  },

  viewAvt(e){
    let src = e.currentTarget.dataset.src;
    wx.previewImage({
      urls: [src,],
    })
  },
  addWechat(){
    let wechat = this.data.person.weChat
    wx.setClipboardData({
      data:wechat,
      success:()=>{
        wx.showToast({
          title: '微信号复制成功',
          icon:'success'
        })
      },
      fail:()=>{
        wx.showToast({
          title: '微信号复制失败!',
          icon: 'none'
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
  },

    getSalesman(){
      let that = this;
      util.post({
        url: 'https://groomtea.icebartech.com/api/miniApp/dealer/findBySalesman',
        success: (res) => {
          console.log('获取业务员----', res)
          app.globalData.userInfo.salesmanCode = res.data.bussData.salesmanCode
          that.setData({
            person: res.data.bussData
          })
        },
        fail: res => {
          console.log(res);
        }
      })
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    let user = app.globalData.userInfo
    if (user.dealerType){
      if (JSON.stringify(that.data.person)=="{}"){
        console.log('用户为经销商帐号');
        that.getSalesman();
      }
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})